package com.common;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class AutoTools {
    public static Map<String,String> paramMap=new HashMap<String,String>();
    public static int createRandomInt(int bound){
        Random random=new Random();
        int nextInt=random.nextInt();
        return nextInt;
    }
    public static String pickRandomString(String... avaliableValue){
        Random random=new Random();
        int indexNext=random.nextInt(avaliableValue.length-1);
        return avaliableValue[indexNext];
    }
    public static String timeStampString(String format){
        SimpleDateFormat sdf=new SimpleDateFormat(format);
        String timeStamp=sdf.format(new Date());
        return timeStamp;
    }
    public static void saveParam(String paramName,String value){
        paramMap.put(paramName,value);
    }
    public static void saveTimeStampParam(String paramName,String initValue,String format){
        paramMap.put(paramName,initValue+timeStampString(format));
    }
    public static String replaceParam(String origin){
        String result=origin;
        for(String key:paramMap.keySet()){
            result=result.replaceAll("\\{"+key+"\\}",paramMap.get(key));

        }
        return result;
    }
}
